package com.isunland.managesystem.ui;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.ScoreType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by wu on 2016/4/25.
 */
public class ChooseScoreTypeDialogFragment extends BaseNetworkDialogFragment {

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    try {
      Type listType = new TypeToken<ArrayList<ScoreType>>() {
      }.getType();

      ArrayList<ScoreType> messageDialogs = new Gson().fromJson(arg0, listType);
      if (messageDialogs == null || messageDialogs.size() == 0) {

        return null;
      }
      for (int i = 0; i < messageDialogs.size(); i++) {
        list.add(new CustomerDialog(messageDialogs.get(i).getName(),
            messageDialogs.get(i).getCustomAttrs()));
      }

      return list;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return list;
  }

  @Override public String getUrl() {

    return ApiConst.URL_DATA_DICTIONARY_LIST;
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<String, String>();
    params.put("memCode", CurrentUser.newInstance(getActivity()).getMemberCode());
    params.put("dictFlg", "Reward_Kind_Code");
    return params;
  }
}
